namespace _131 {

var hasCycle = function(head: ListNode<number>): boolean {
    for(var x = head; x !== null && x.next !== head; x = x.next) ;
    return x !== null && x.next === head;
};

function ofArray(xs: number[]): ListNode<number> {
    var tail: ListNode<number> = null;
    for(var i = xs.length - 1; i >= 0; i--) {
        tail = { val: xs[i], next: tail }
    }
    return tail;
}

console.assert ( hasCycle(null) === false )
var x: ListNode<number> = { val: 1, next: null }
//console.assert ( hasCycle(x ) === false )
x.next = x
//console.assert ( hasCycle(x ))

x = ofArray([3,2,0,-4])
x.next.next.next.next = x

console.assert( hasCycle(x))
}